<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
	<link id="easyuiTheme" rel="stylesheet" type="text/css" href="../jquery-easyui-1.5.3/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../jquery-easyui-1.5.3/themes/icon.css"/>
    <!--<link rel="stylesheet" type="text/css" href="../jquery-easyui-1.5.3/demo/demo.css"/> -->
    <script type="text/javascript" src="../jquery-easyui-1.5.3/jquery.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
	    var contextPath = function() {
	        return  "/" + location.pathname.split("/")[1];
	    }
	    
		function getValue(name){
			var str=window.location.search;
			if (str.indexOf(name)!=-1){
				var pos_start=str.indexOf(name)+name.length+1;
				var pos_end=str.indexOf("&",pos_start);
				if (pos_end==-1){
					return str.substring(pos_start);
				} else {
					return str.substring(pos_start,pos_end);
				}
			} else {
				return "";
			}
		}
		
		var  themeName = getValue("theme");
		if (themeName!=""){
		    var cssurl  = $('#easyuiTheme').attr('href');  
		    var href = cssurl.substring(0, cssurl.indexOf('themes')) + 'themes/' + themeName + '/easyui.css';  
		    $('#easyuiTheme').attr('href', href);  
		}
	</script>

</head>

<style>
    .datagrid-btable{
        width:100%;
    }
    .datagrid-header-inner{
        width:100%;
    }
    .datagrid-header{
        width:100%;
    }
    .datagrid-htable{
        width:100%;
    }
    .datagrid-cell{margin:auto;}
    .fitem{text-align:center}
    .ftitle{text-align:center}
</style>

<body>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',title:'保单信息导入等待池'">	  
        <table id="datagrid"  class="easyui-datagrid" style="width:100%;height:100%"></table>
        <div id="dgtoolbar">		
        	<form name="searchform" method="post" action="" id ="searchform">
				<td width="70" height="30">
					<strong>接件日期：</strong>
				    <input class="easyui-textbox" type="text" id="search_username" name="username" size=20 >
				</td>			
				<td width="70" height="30">
					<strong>投保日期：</strong>
				    <input class="easyui-textbox" type="text" id="search_usercn" name="userCN" size=20 >
				</td>
				<td height="30">
				    <a id="submit_search">搜索</a>
				    <a id="reset_search">重置</a>
				</td>
			</form>
            <a id="btn_import" href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" >导入正式库</a>
            <a id="btn_edit" href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" >修改信息</a>
            <a id="btn_delete" href="#" class="easyui-linkbutton" iconCls="icon-cancel" plain="true" >删除数据</a>
        </div>
    </div>
</div>


</body>

<script type="text/javascript">

    $(function () {

		//touch页面,记录用户进入页面
		$.ajax({
			url : contextPath()+"/mdmis/touch",
			type : "get",
			data : {
				//"traceRandom":trace_random,
				//"recordID":trace_recordID,
				"target":location.pathname,
				"operation":"[进入页面]保单等待导入池"
			},
			dataType : "json",	// 数据返回类型
		    cache : false, 	// 是否缓存
		    async : true   	// 默认为true 异步请求
		});
    	
    	$('#datagrid').datagrid({
    		loadMsg:'正在加载数据...',
    	    url:contextPath()+'/mdmis/getPolicyImportPool',
    	    toolbar:'#dgtoolbar',
    	    queryParams: form2Json("searchform"),
    	    pagination: true,
            pageSize:'100',
            pageList:[100,300,500],            
            rownumbers: true,
            striped: true,
            fit: true,
            fitColumns: false, //不自动适应列宽
            singleSelect: false, 
            selectOnCheck: true,
            checkOnSelect: true,
    	    columns:[[
    			{field:'ck',checkbox:true}, 
    			{field:'insure_no',title:'投保单号',width:130},
    			{field:'project',title:'所属项目',width:60},
    			{field:'policy_type',title:'保单类型',width:60},
    			{field:'intro_time',title:'接件日期',width:80},
    			{field:'insure_time',title:'投保日期',width:80},
    			{field:'applicant',title:'投保人',align:'center',width:60},
    			{field:'mobilephone',title:'手机',width:100},
    			{field:'address',title:'地址',width:300},
    			{field:'product',title:'险种名称',width:300},
    			{field:'premium',title:'保费',align:'right',width:60},
    			{field:'tsr_name',title:'TSR姓名',align:'center',width:60},
    			{field:'tsr_group',title:'TSR小组',align:'center',width:60},
    			{field:'remark',title:'备注',width:600}
    	    ]]
    	});  
    	
    	  
		//点击搜索
		$("#submit_search").linkbutton({ iconCls: 'icon-search', plain: true }).click(function () {
            $('#datagrid').datagrid({ queryParams: form2Json("searchform") });   
        });
		//点击重置
		$("#reset_search").linkbutton({ iconCls: 'icon-reload', plain: true }).click(function () {
            $('#search_username').textbox('setValue',''); //将用户名的输入框清空
            $('#search_usercn').textbox('setValue',''); //将中文名的输入框清空
            //$('#datagrid').datagrid('reload');  
            $('#datagrid').datagrid({ queryParams: form2Json("searchform") });   
        });
		//点击导入
		$("#btn_import").linkbutton({ iconCls: 'icon-redo', plain: true }).click(function () {
		      var rows = $('#datagrid').datagrid('getSelections');
		      if (rows){
		          $.messager.confirm('Confirm','确定要导入所选择的数据?',function(r){
		              if (r){
		            	  var ids="";
		            	  for (var i in rows){
		            		  ids += rows[i].insure_no+",";
		            	  }
		            	  $.ajax({
		            		    type:'POST',
		            		    url:contextPath()+'/mdmis/importPolicy',
		            		    data:{insureNos:ids},
		            		    dataType:'json',
		            		    beforeSend: function () {
									$.messager.progress({ 
			            		       　	title: '提示', 
										msg: '操作进行中，请稍候……', 
										text: '' 
									});
		            		    },
		            		    complete: function () {
		            		         $.messager.progress('close');
		            		    },
		            		    success:function(result){
			                          $('#datagrid').datagrid('reload');	// reload data
				                      if (result.success){
				                          $.messager.show({
				                              title: 'Success',
				                              msg: '操作完成！'
				                          });
				                      } else {
				                          $.messager.show({	// show error message
				                              title: 'Error',
				                              msg: result.errMsg
				                          });
				                      }
			            		}
							});
		              }
		          });
		      }
        });
		//点击删除
		$("#btn_delete").linkbutton({ iconCls: 'icon-cancel', plain: true }).click(function () {
		      var rows = $('#datagrid').datagrid('getSelections');
		      if (rows){
		          $.messager.confirm('Confirm','确定要删除所选择的数据?',function(r){
		              if (r){
		            	  var ids="";
		            	  for (var i in rows){
		            		  ids += rows[i].insure_no+",";
		            	  }
		                  $.post(contextPath()+'/mdmis/removeTempPolicy',{insureNos:ids},function(result){
		                      if (result.success){
		                          $('#datagrid').datagrid('reload');	// reload data
		                          $.messager.show({
		                              title: 'Success',
		                              msg: '操作完成！'
		                          });
		                      } else {
		                          $.messager.show({	// show error message
		                              title: 'Error',
		                              msg: result.errMsg
		                          });
		                      }
		                  },'json');
		              }
		          });
		      }
        });
    })
    
    //将表单数据转为json
    function form2Json(id) {
        var arr = $("#" + id).serializeArray();
        var jsonStr = "";
        jsonStr += '{';
        for (var i = 0; i < arr.length; i++) {
            jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
        }
        jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
        jsonStr += '}';
        var json = JSON.parse(jsonStr);
        return json;
    }
</script>


</html>



